$(document).ready(function(){
	$("#email").blur(function(){ 
	var email = $("#email").val();
	var msgbox = $("#msg_email");
	var email_pat = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(email == ""){
		msgbox.html('<span class="notice-error">Không bỏ trống</span>');
	}
	else if(email.length > 3 && email_pat.test(email) ){
	$("#msg_email").html('<img src="images/loader.gif" align="absmiddle">&nbsp;Kiểm tra...');

	$.ajax({  
	    type: "POST",  
	    url: "check_email_ajax.php",  
	    data: "email="+ email,  
	    success: function(msg){  
	   
	   $("#msg_email").ajaxComplete(function(event, request){ 

		if(msg == 'OK')
		{ 
		    $("#email").removeClass().addClass('notice-success');
	        msgbox.html('<span class="notice-success">Chuẩn men</span>');
		}  
		else  
		{  
		     $("#email").removeClass().addClass("notice-error");
			msgbox.html(msg);
		}  
	   
	   });
	   } 
	   
	  }); 

	}
	else
	{
		$("#email").removeClass().addClass("notice-error");
		$("#msg_email").html('<span class="notice-error">Email không hợp lệ</span>').fadeIn();
	}
	return false;
	});

});